{##
 # Contains macros for decoration of elements.
 #
 # @copyright  Copyright (c) 2010-2012 The Fajr authors (see AUTHORS).
 #             Use of this source code is governed by a MIT license that can be
 #             found in the LICENSE file in the project root directory.
 # @author     Michal Hozza
 #}

{# Note: All macros in decorators take SAFE values and they are NOT escaped #}

{##
 # Spravi content "rozklikavaci"
 # @param safeHtml $title nazov
 # @param safeHtml $content obsah rozklikavacieho elementu
 # @param bool $collapsed ma byt defaultne skryty?
 #}
{% macro collapsible(title, content, collapsed) %}
  {% set id = 'collapsible' ~ unique_id() %}
  <div class="collapsible" id="{{ id }}">
    <div class="collapsibleheader togglevisibility" onclick="toggleVisibility('{{ id }}')">
      {{ title|raw }}
    </div>
    <div class="collapsiblecontent">
      {{ content|raw }}
    </div>
    {% if collapsed %}
      <script type="text/javascript">
        toggleVisibility("{{ id }}");
      </script>
    {% endif %}
  </div>
{% endmacro %}

{##
 # Zobrazi tabulku dat.
 #
 # @param safeString $class css trieda, pouzita ako colorstyle-sorting$class
 # @param safeHtml $head content hlavicky tabulky (obsah v ramci prveho <tr>)
 # @param safeHtml $body content riadkov z obsahom tabulky
 # @param safeHtml $foot content footera
 # @param bool $empty zobrazit informacie o neexistencii udajov namiesto tabulky?
 # @param bool $collapsed ma byt defaultne skryty?
 #}
{% macro table(class, head, body, foot, empty) %}
  {% if empty %}
    <font color="red"> Dáta pre túto tabuľku neboli nájdené.</font><hr class="space" />
  {% else %}
    {% if class != "" %}
      {% set class=" "+class %}
    {% endif %}
    <table id="table{{ unique_id() }}" class="colstyle-sorting{{ class }}">
      <thead>
        <tr>
          {{ head|raw }}
        </tr>
      </thead>
      {# tu by mal byt po spravnosti tfoot, aby bol vystup validny
         lenze to je treba najprv upravit ten triediaci skript
         (pri tlaci chceme totiz tfoot iba na spodu bez opakovania)
         jedna moznost je nepouzit tfoot, ale tbody s nejakym classom
      #}
      <tbody>
        {{ body|raw }}
      </tbody>
      {% if foot %}
        <tfoot>
          {{ foot|raw }}
        </tfoot>
      {% endif %}
   {% endif %}
  </table>
{% endmacro %}

{##
  # Obali text tagom <span> s class.
  #
  # @param safeString $text text, ktory treba obalit 
  # @param safeString $class class, ktora sa ma pouzit
  ##}

{% macro span(text,class) %}
  <span class="{{class}}">{{text | raw}}</span>
{% endmacro %}

{##
  # Vyrobi riadok rozklikavacieho bloku.
  #
  # @param safeHTML $head hlavicka
  # @param safeHTML $body obycajny text
  ##}

{% macro riadok(head,body) %}
  <li class="table_box">{{_self.span(head,"head")}} {{_self.span(body,"body")}}</li>
{% endmacro %}

{##
  # Zobrazi content, alebo informacie o neexistencii udajov
  #
  # @param safeHTML $content obsah, ktory sa ma zobrazit
  # @param bool $empty zobrazit informacie o neexistencii udajov namiesto obsahu?
  ##}

{% macro printbox(content,empty) %}
  {% if empty %}
    <span class="empty_content"> Dáta pre túto tabuľku neboli nájdené.</span><hr class="space" />
  {% else %}
    {{ content | raw}}
  {% endif%}
{% endmacro %}

